package com.zzty.demo.service.impl;

import com.zzty.demo.dao.UserDao;
import com.zzty.demo.dao.UserMapper;
import com.zzty.demo.entity.Clazz;
import com.zzty.demo.entity.User;
import com.zzty.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Autowired
    UserMapper userMapper;


    @Override
    public User getUserByOpenId(User user) {
        User user1=userDao.getUserByOpenId(user);
        return user1;
    }

    @Override
    public Integer updateOpenIdToUser(User user) {
        Integer count=userDao.updateOpenIdToUser(user);
        return count;
    }

    @Override
    public User getUserByName(User user) {
        User user1=userDao.getUserByName(user);
        return user1;
    }

    @Override
    public List<User> getAllUsers() {
        List<User> users=userDao.getAllUsers();
        return users;
    }

    @Override
    public List<User> getUserByClazzId(Integer id) {
        List<User> users=userDao.getUserByClazzId(id);
        return users;
    }

    @Override
    public User getUserById(User user) {
        User user1=userDao.getUserById(user);
        return user1;
    }
    @Override
    public User getUserById1(Integer id) {
        User user=userDao.getUserById1(id);
        return user;
    }

    @Override
    public User getUserByOpenId(String openId) {
        User user1 = userMapper.getUserByOpenId(openId);
        return user1;
    }

    @Override
    public User getUserByName(String name) {
        System.out.println("USI name: "+name);
        User user = userMapper.getUserByName(name);
        return user;
    }

    @Override
    public List<User> getUserByClazzid(Clazz clazz) {
        List<User> users = userMapper.getUserByClazzid(clazz);
        if (users == null || users.isEmpty()) {
            return null;
        } else {
            return users;
        }
    }

    @Override
    public User getUserById(Integer id) {
        User user = userMapper.getUserById(id);
        if (user != null) {
            return user;
        } else {
            return null;
        }
    }

    @Override
    public Integer addUser(User user) {
        Integer count = userMapper.addUser(user);
        return count;
    }

    @Override
    public List<User> getUser2ById(User user) {
        List<User> users=userMapper.getUser2ById(user);
        System.out.println("Users========"+users.toString());
        return users;
    }

    @Override
    public Integer updateImgByUserId(Integer id, String img) {
        Integer count=userDao.updateImgByUserId(id,img);
        return count;
    }

    @Override
    public Integer updateUser(User user) {
        Integer result=userDao.updateUser(user);
        return result;
    }
}
